<?php
/**
 * alltosun.com admin_log_helper.php
 * ============================================================================
 * 版权所有 (C) 2009-2011 北京互动阳光科技有限公司，并保留所有权利。
 * 网站地址: http://www.alltosun.com
 * ----------------------------------------------------------------------------
 * 许可声明：这是一个开源程序，未经许可不得将本软件的整体或任何部分用于商业用途及再发布。
 * ============================================================================
 * $Author: 高昂 (gaoa@alltosun.com) $
 * $Date: 2016-4-1 下午3:04:23 $
 * $Id: $
 */

class admin_log_helper
{
    /**
     * 自动写入log操作日志
     * @param unknown $module
     * @param unknown $controller
     * @param unknown $action
     * @param unknown $request
     */
    public static function write_admin_log($module, $controller, $action, $request = array()) {

        $log_info = array();
        $log_info['admin_id'] = user_helper::get_admin_id();
        $log_info['res_id']   = @$request['id'] ? $request['id'] : 0;
        $log_info['add_time'] = date('Y-m-d H:i:s');
        $log_info['extra']    = is_array($request) ? json_encode($request) : $request;
        $log_info['res_name'] = $module;

        $arr = explode('_', $controller);
        $action_type = $arr[0];
        $log_info['action']   = $action_type;

        if (in_array($action_type, admin_log_config::$action_list)) {
            _model('admin_log')->create($log_info);
        }
    }

    /**
     * 手工调用写入log操作日志
     * @param unknown_type $module
     * @param unknown_type $controller
     * @param unknown_type $action
     * @param unknown_type $request
     */
    public static function call_write_admin_log($module, $controller, $action, $request = array()) {

        $log_info = array();
        $log_info['admin_id'] = user_helper::get_admin_id();
        $log_info['res_id']   = @$request['id'] ? $request['id'] : 0;
        $log_info['add_time'] = date('Y-m-d H:i:s');
        $log_info['extra']    = is_array($request) ? json_encode($request) : $request;
        $log_info['res_name'] = $module;

        $log_info['action']   = $action;

        _model('admin_log')->create($log_info);
    }

}



?>